package org.future.task.redis.cluster;

import redis.clients.jedis.Pipeline;

public abstract class AbstractCommand implements Command {

    @Override
    public void exec(Pipeline pipeline, CEntry centry) {
        if (Assert.allNullCEntry(centry)) {
            return;
        }

        switch (centry.getCtype()) {
            case HSET:
                pipeline.hset(centry.getBigKey(), centry.getKey(), centry.getVal());
                break;
            case SET:
                pipeline.set(centry.getBigKey(), centry.getVal());
                break;
            case HMSET:
                pipeline.hmset(centry.getBigKey(), centry.getFullData());
                break;
            default:
                expand(pipeline, centry);
        }

        if (centry.getTtl() != -1) {
            pipeline.expire(centry.getBigKey(), centry.getTtl());
        }
    }

    public abstract void expand(Pipeline pipeline, CEntry cEntry);

}
